//
//  PKRootRightViewController.m
//  PianKe
//
//  Created by lanou on 15/9/25.
//  Copyright (c) 2015年 李伟伟. All rights reserved.
//

#import "PKRootRightViewController.h"
#import "PKBaseViewController.h"
@interface PKRootRightViewController ()
@property(nonatomic, strong)NSArray *classArray;
@property(nonatomic, strong)PKBaseViewController *baseVC;
@property(nonatomic, strong)UINavigationController *navi;
@end

@implementation PKRootRightViewController

//ARC 和MRC都不能手动调用dealloc只能重写   ARC重写的时候不能再dealloc方法 内部调用[super dealloc]  一般会用于移除观察者、代理对象置空;


-(NSArray *)classArray
{
    if (!_classArray) {
        _classArray = @[@"PKProductMainViewController",@"PKReadMainViewController",@"PKGroupMainViewController",@"PKRadioMainViewController"];
    }
    return _classArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    _baseVC = [[NSClassFromString(self.classArray[0]) alloc]init];
    
    
    //创建一个导航控制器 管理将要显示的详情页面，这样 将要显示的界面才有push功能，因为导航控制器需要一直存在，所以可以吧它定义为一个属性
    _navi = [[UINavigationController alloc]initWithRootViewController:_baseVC];
    _navi.navigationBar.hidden = YES;//不需要导航栏
    _baseVC.changeFrameVC = self;
    [self.view addSubview:_navi.view];
}

-(void)changeFrame
{
    
    
    CGRect newFrame = self.view.frame;
    if (newFrame.origin.x == 0) {
        newFrame.origin.x = SCREEN_WITDTH - 40;
    }else
    {
        newFrame.origin.x = 0;
    }
   [UIView animateWithDuration:0.5 animations:^{
       self.view.frame = newFrame;
   }];
    
}

-(void)changeViewWithIndex:(NSInteger)index
{

    //用NSClassFromString 函数 通过字符串获取到某个类 然后动态地创建不同的控制器  同事使用多态的思想让父类指针授予子类对象
        
    [_navi.view removeFromSuperview];
    _baseVC = [[NSClassFromString(self.classArray[index]) alloc]init];
    
    _navi = [[UINavigationController alloc]initWithRootViewController:_baseVC];
    _baseVC.changeFrameVC = self;
    [self.view addSubview:_navi.view];
    _navi.navigationBar.hidden = YES;//不需要导航栏
    [self changeFrame];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
